package com.icloud.cer.rest.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class JsonUtil {
	private static GsonBuilder DEFAULT = new GsonBuilder();
	private static Gson DEFAULT_GSON;
	public static final String EMPTY_JSON = "{}";
	public static final String EMPTY_JSON_ARRAY = "[]";
	
	public static Gson getDefault() {
		synchronized (DEFAULT) {
			if (DEFAULT_GSON != null)
				return DEFAULT_GSON;		
			DEFAULT_GSON = DEFAULT.create();
		}
		return DEFAULT_GSON;
	}
	
	public static String serialize(Object src) {
		if (src == null) {
			return EMPTY_JSON;
		}
		return getDefault().toJson(src);
	}
	
	
}
